package com.hzcx.app.simplechat.ui.chat.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.chat.bean.ChatCollectBean;
import com.hzcx.app.simplechat.util.dp.DpUtils;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.glide.GlideUtils;

import java.util.List;

public class ChatCollectAdapter extends BaseQuickAdapter<ChatCollectBean, BaseViewHolder> {
    public ChatCollectAdapter(@Nullable List<ChatCollectBean> data) {
        super(R.layout.rv_item_chat_collect, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChatCollectBean item) {
        TextView tvContent,tvDate;
        ImageView ivImg;
        tvContent=helper.getView(R.id.tv_content);
        ivImg=helper.getView(R.id.iv_img);
        tvDate=helper.getView(R.id.tv_date);

        tvDate.setText(item.getNickname() + "    " + item.getCreatetime());

        if (EmptyUtils.isEmpty(item.getCollectimage())) {
           tvContent.setText(item.getCollectdetail());
           tvContent.setVisibility(View.VISIBLE);
            ivImg.setVisibility(View.GONE);

            ConstraintLayout.LayoutParams params=new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.topToBottom=R.id.tv_content;
            params.topMargin= DpUtils.dp2px(mContext,20);
            params.leftToLeft=0;
            params.leftMargin=DpUtils.dp2px(mContext,15);
            tvDate.setLayoutParams(params);

        } else {
            GlideUtils.loadImgAsCenter(mContext, item.getCollectimage(), ivImg);
            tvContent.setVisibility(View.GONE);
            ivImg.setVisibility(View.VISIBLE);

            ConstraintLayout.LayoutParams params=new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.topToBottom=R.id.iv_img;
            params.topMargin= DpUtils.dp2px(mContext,20);
            params.leftToLeft=0;
            params.leftMargin=DpUtils.dp2px(mContext,16);
            tvDate.setLayoutParams(params);
        }

        helper.addOnClickListener(R.id.tv_delete,R.id.cons_content);
    }

}
